﻿/****************************** Module Header ******************************\
 * Module Name:  JSlider.cs
 * Module Version:  1.0.0 (2012-10-17)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This componse is use for image slider.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace UCL.Web.CustomControls
{
    /// <summary>
    /// 图片幻灯片插件
    /// <example>
    /// <![CDATA[
    /// <so:JSlider runat="server" ID="aa"><a href="#aa"><img src="a.png" alt="" title="helsdfsaf" /></a><img src="b.png" title="nivoslider-125-caption-0" alt="" /></so:JSlider>
    /// ]]>
    /// </example>
    /// </summary>
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:JSlider runat=server></{0}:JSlider>")]
    public class JSlider : HtmlContainerControl
    {
        protected override void OnPreRender(System.EventArgs e)
        {
            Page.PreRenderComplete += PagePreRenderComplete;
            base.OnPreRender(e);
        }
        private void PagePreRenderComplete(object s, EventArgs e)
        {
            this.ID = this.UniqueID.Replace('$', '_');
            this.ClientIDMode = ClientIDMode.Static;
            Page.RegisterHeaderLink("nivo-slider-css", "/DMS/Skin/Js/JqPlus/nivo-slider/3.1/nivo-slider.css");
            Page.RegisterHeaderLink("nivo-slider-theme", "/DMS/Skin/Js/JqPlus/nivo-slider/3.1/themes/default/default.css");
            Page.ClientScript.RegisterClientScriptInclude(typeof(Page), "nivo-slider-js", "/DMS/Skin/Js/JqPlus/nivo-slider/3.1/jquery.nivo.slider.pack.js");
            Page.ClientScript.RegisterStartupScript(typeof(Page), this.ID, string.Format("jQuery('#{0}').nivoSlider({{controlNav:false}});", this.ID), true);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(string.Format("<div class=\"slider-wrapper theme-default\"><div class=\"ribbon\"></div><div id=\"{0}\" class=\"nivoSlider\">", this.ID));
            base.RenderChildren(writer);
            writer.Write("</div></div>");
        }
    }
}
